(()=>{var F=class{static getScreenWidth(){return window.innerWidth||document.documentElement.clientWidth}static getScreenHeight(){return window.innerHeight||document.documentElement.clientHeight}static isNotValidScreensize(e,t){const s=this.getScreenWidth(),i=this.getScreenHeight(),l=e&&(s>t.width||i>t.height),r=!e&&(s=0&&e.right>=0&&e.top<=(window.innerHeight||document.documentElement.clientHeight)&&e.left<=(window.innerWidth||document.documentElement.clientWidth)}static isPageScrolled(){return window.pageYOffset>0||document.documentElement.scrollTop>0}},E=F,C=class{constructor(e,t){this.config=e,this.performanceImages=[],this.logger=t}async run(){try{const e=this._generateLcpCandidates(1/0);e&&(this._initWithFirstElementWithInfo(e),this._fillATFWithoutDuplications(e))}catch(e){this.errorCode="script_error",this.logger.logMessage("Script Error: "+e)}}_generateLcpCandidates(e){const t=document.querySelectorAll(this.config.elements);return t.length<=0?[]:Array.from(t).map(l=>{if(l.nodeName.toLowerCase()==="img"&&l.parentElement.nodeName.toLowerCase()==="picture")return null;let r;if(l.nodeName.toLowerCase()==="picture"){const a=l.querySelector("img");if(a)r=a.getBoundingClientRect();else return null}else r=l.getBoundingClientRect();return{element:l,rect:r}}).filter(l=>l!==null).filter(l=>l.rect.width>0&&l.rect.height>0&&E.isIntersecting(l.rect)).map(l=>({item:l,area:this._getElementArea(l.rect),elementInfo:this._getElementInfo(l.element)})).sort((l,r)=>r.area-l.area).slice(0,e).map(l=>({element:l.item.element,elementInfo:l.elementInfo}))}_getElementArea(e){const t=Math.min(e.width,(window.innerWidth||document.documentElement.clientWidth)-e.left),s=Math.min(e.height,(window.innerHeight||document.documentElement.clientHeight)-e.top);return t*s}_getElementInfo(e){const t=e.nodeName.toLowerCase(),s={type:"",src:"",srcset:"",sizes:"",sources:[],bg_set:[],current_src:""},i=/url\(\s*?['"]?\s*?(.+?)\s*?["']?\s*?\)/ig;if(t==="img"&&e.srcset)s.type="img-srcset",s.src=e.src,s.srcset=e.srcset,s.sizes=e.sizes,s.current_src=e.currentSrc;else if(t==="img")s.type="img",s.src=e.src,s.current_src=e.currentSrc;else if(t==="video"){s.type="img";const l=e.querySelector("source");s.src=e.poster||(l?l.src:""),s.current_src=s.src}else if(t==="svg"){const l=e.querySelector("image");l&&(s.type="img",s.src=l.getAttribute("href")||"",s.current_src=s.src)}else if(t==="picture"){s.type="picture";const l=e.querySelector("img");s.src=l?l.src:"",s.sources=Array.from(e.querySelectorAll("source")).map(r=>({srcset:r.srcset||"",media:r.media||"",type:r.type||"",sizes:r.sizes||""}))}else{const r=[window.getComputedStyle(e,null).getPropertyValue("background-image"),getComputedStyle(e,":after").getPropertyValue("background-image"),getComputedStyle(e,":before").getPropertyValue("background-image")].filter(o=>o!=="none");if(r.length===0)return null;const a=r[0];if(s.type="bg-img",a.includes("image-set(")&&(s.type="bg-img-set"),!a||a===""||a.includes("data:image"))return null;const n=[...a.matchAll(i)];if(s.bg_set=n.map(o=>o[1]?{src:o[1].trim()+(o[2]?" "+o[2].trim():"")}:{}),s.bg_set.every(o=>o.src==="")&&(s.bg_set=n.map(o=>o[1]?{src:o[1].trim()}:{})),s.bg_set.length<=0)return null;s.bg_set.length>0&&(s.src=s.bg_set[0].src,s.type==="bg-img-set"&&(s.src=s.bg_set))}return s}_initWithFirstElementWithInfo(e){const t=e.find(s=>s.elementInfo!==null&&(s.elementInfo.src||s.elementInfo.srcset));if(!t){this.logger.logMessage("No LCP candidate found."),this.performanceImages=[];return}this.performanceImages=[{...t.elementInfo,label:"lcp"}]}_fillATFWithoutDuplications(e){e.forEach(({element:t,elementInfo:s})=>{this._isDuplicateImage(t)||!s||this.performanceImages.push({...s,label:"above-the-fold"})})}_isDuplicateImage(e){const t=this._getElementInfo(e);if(t===null)return!1;const s=t.type==="img"||t.type==="img-srcset"||t.type==="video",i=t.type==="bg-img"||t.type==="bg-img-set"||t.type==="picture";return(s||i)&&this.performanceImages.some(l=>l.src===t.src)}getResults(){return this.performanceImages}},v=C,x=class{constructor(e,t){this.config=e,this.logger=t,this.lazyRenderElements=[]}async run(){try{const e=this._getLazyRenderElements();e&&this._processElements(e)}catch(e){this.errorCode="script_error",this.logger.logMessage("Script Error: "+e)}}_getLazyRenderElements(){const e=document.querySelectorAll("[data-rocket-location-hash]"),t=this._getSvgUseTargets();return e.length<=0?[]:Array.from(e).filter(i=>this._skipElement(i)?!1:t.includes(i)?(this.logger.logColoredMessage(`Element skipped because of SVG: ${i.tagName}`,"orange"),!1):!0).map(i=>({element:i,depth:this._getElementDepth(i),distance:this._getElementDistance(i),hash:this._getLocationHash(i)}))}_getElementDepth(e){let t=0,s=e.parentElement;for(;s;)t++,s=s.parentElement;return t}_getElementDistance(e){const t=e.getBoundingClientRect(),s=window.pageYOffset||document.documentElement.scrollTop;return Math.max(0,t.top+s-E.getScreenHeight())}_skipElement(e){const t=this.config.skipStrings||["memex"];return!e||!e.id?!1:t.some(s=>e.id.toLowerCase().includes(s.toLowerCase()))}_shouldSkipElement(e,t){if(!e)return!1;for(let s=0;sparseFloat(s[a])<0);return(l||s.contentVisibility==="auto"||s.contentVisibility==="hidden")&&t.push({element:e,conflicts:[l&&"negative margin",s.contentVisibility==="auto"&&"content-visibility:auto",s.contentVisibility==="hidden"&&"content-visibility:hidden"].filter(Boolean)}),Array.from(e.children).forEach(a=>{const n=window.getComputedStyle(a),c=["marginTop","marginRight","marginBottom","marginLeft"].some(h=>parseFloat(n[h])<0);(c||n.position==="absolute"||n.position==="fixed")&&t.push({element:a,conflicts:[c&&"negative margin",n.position==="absolute"&&"position:absolute",n.position==="fixed"&&"position:fixed"].filter(Boolean)})}),t}_processElements(e){e.forEach(({element:t,depth:s,distance:i,hash:l})=>{if(this._shouldSkipElement(t,this.config.exclusions||[])||l==="No hash detected")return;const r=this._checkLcrConflict(t);if(r.length>0){this.logger.logMessage("Skipping element due to conflicts:",r);return}const a=t.parentElement&&this._getElementDistance(t.parentElement)=this.config.lrc_threshold,n=a?"green":i===0?"red":"";this.logger.logColoredMessage(`${" ".repeat(s)}${t.tagName} (Depth: ${s}, Distance from viewport bottom: ${i}px)`,n),this.logger.logColoredMessage(`${" ".repeat(s)}Location hash: ${l}`,n),this.logger.logColoredMessage(`${" ".repeat(s)}Dimensions Client Height: ${t.clientHeight}`,n),a&&(this.lazyRenderElements.push(l),this.logger.logMessage(`Element pushed with hash: ${l}`))})}_getXPath(e){return e&&e.id!==""?`//*[@id="${e.id}"]`:this._getElementXPath(e)}_getElementXPath(e){if(e===document.body)return"/html/body";const t=this._getElementPosition(e);return`${this._getElementXPath(e.parentNode)}/${e.nodeName.toLowerCase()}[${t}]`}_getElementPosition(e){let t=1,s=e.previousElementSibling;for(;s;)s.nodeName===e.nodeName&&t++,s=s.previousElementSibling;return t}_getLocationHash(e){return e.hasAttribute("data-rocket-location-hash")?e.getAttribute("data-rocket-location-hash"):"No hash detected"}_getSvgUseTargets(){const e=document.querySelectorAll("use"),t=new Set;return e.forEach(s=>{let i=s.parentElement;for(;i&&i!==document.body;)t.add(i),i=i.parentElement}),Array.from(t)}getResults(){return this.lazyRenderElements}},M=x,B=class{constructor(e,t){this.config=e,this.logger=t,this.aboveTheFoldFonts=[];const s=(Array.isArray(this.config.processed_extensions)&&this.config.processed_extensions.length>0?this.config.processed_extensions:["woff","woff2","ttf"]).map(i=>i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|");this.FONT_FILE_REGEX=new RegExp(`\\.(${s})(\\?.*)?$`,"i"),this.EXCLUDED_TAG_NAMES=new Set(["BASE","HEAD","LINK","META","STYLE","TITLE","SCRIPT","IMG","VIDEO","AUDIO","EMBED","OBJECT","IFRAME","NOSCRIPT","TEMPLATE","SLOT","CANVAS","SOURCE","TRACK","PARAM","USE","SYMBOL","BR","HR","WBR","APPLET","ACRONYM","BGSOUND","BIG","BLINK","CENTER","FONT","FRAME","FRAMESET","MARQUEE","NOFRAMES","STRIKE","TT","U","XMP"])}isExcluded(e,t){const s=this.config.preload_fonts_exclusions,i=new Set(s);return!!(i.has(e)||s.some(l=>e.includes(l))||Array.isArray(t)&&t.length>0&&(t.some(l=>i.has(l))||t.some(l=>s.some(r=>l.includes(r)))))}canElementBeStyledWithFontFamily(e){return!this.EXCLUDED_TAG_NAMES.has(e.tagName)}isElementVisible(e){const t=window.getComputedStyle(e),s=e.getBoundingClientRect();return this.hasTransparentText(e)?!1:!(t.display==="none"||t.visibility==="hidden"||t.opacity==="0"||s.width===0||s.height===0)}hasTransparentText(e){const t=window.getComputedStyle(e),s=t.color||"",i=t.filter||"";return!!(s==="transparent"||s.match(/rgba\(\d+,\s*\d+,\s*\d+,\s*0\)/)||s.match(/hsla\(\d+,\s*\d+%,\s*\d+%,\s*0\)/)||s.match(/#[0-9a-fA-F]{6}00/)||i.includes("opacity(0)"))}cleanUrl(e){try{return e=e.split("?")[0].split("#")[0],new URL(e,window.location.href).href}catch{return e}}async externalStylesheetsDoc(){function e(n){const o={};function c(h){if(!h)return null;const u=h.match(/url\s*\(\s*(['"]?)(.+?)\1\s*\)/);return u?u[2]:null}function g(h){return h?h.replace(/^['"]+|['"]+$/g,"").trim():""}return!n||!Array.isArray(n)?(console.warn("generateFontPairsFromStyleSheets: Input is not a valid array. Received:",n),o):(n.length===0||n.forEach(h=>{if(h&&h.cssRules)try{for(const u of h.cssRules)if(u.type===CSSRule.FONT_FACE_RULE){const m=u,d=g(m.style.getPropertyValue("font-family")),f=m.style.getPropertyValue("font-weight")||"normal",p=m.style.getPropertyValue("font-style")||"normal",S=m.style.getPropertyValue("src"),y=c(S);if(d&&y){const w={family:d,weight:f,style:p};o[y]||(o[y]=[]),o[y].some(b=>b.family===w.family&&b.weight===w.weight&&b.style===w.style)||o[y].push(w)}}}catch(u){console.warn("Error processing CSS rules from a stylesheet:",u,h)}else h&&!h.cssRules&&console.warn("Skipping a stylesheet as its cssRules are not accessible or it is empty:",h)}),o)}const t=["fonts.googleapis.com","fonts.gstatic.com","use.typekit.net","fonts.adobe.com","cdn.fonts.net"],s=[...document.querySelectorAll('link[rel="stylesheet"]')].filter(n=>t.some(o=>n.href.includes(o)));if(s.length===0)return this.logger.logMessage("No external CSS links found to process."),{styleSheets:[],fontPairs:{}};const i=s.map(n=>fetch(n.href,{mode:"cors"}).then(o=>o.ok?o.text():(console.warn(`Failed to fetch external CSS from ${n.href}: ${o.status} ${o.statusText}`),null)).catch(o=>(console.error(`Network error fetching external CSS from ${n.href}:`,o),null))),l=await Promise.all(i),r=[];l.forEach(n=>{if(n&&n.trim()!=="")try{const o=new CSSStyleSheet;o.replaceSync(n),r.push(o)}catch(o){console.error("Could not parse fetched CSS into a stylesheet:",o,` CSS (first 200 chars): ${n.substring(0,200)}...`)}}),r.length>0?this.logger.logMessage(`[Beacon] ${r.length} stylesheet(s) fetched and parsed into CSSStyleSheet objects.`):this.logger.logMessage("[Beacon] No stylesheets were successfully parsed from the fetched CSS.");const a=e(r);return{styleSheets:r,fontPairs:a}}async _initializeExternalFontSheets(){this.logger.logMessage("Initializing external font stylesheets...");try{const e=await this.externalStylesheetsDoc();this.externalParsedSheets=e.styleSheets||[],this.externalParsedPairs=e.fontPairs||[],this.logger.logMessage(`Successfully parsed ${this.externalParsedSheets.length} external font stylesheets.`)}catch(e){this.logger.logMessage("Error initializing external font stylesheets:",e),this.externalParsedSheets=[]}}getNetworkLoadedFonts(){return new Map(window.performance.getEntriesByType("resource").filter(e=>this.FONT_FILE_REGEX.test(e.name)).map(e=>[this.cleanUrl(e.name),e.name]))}async getFontFaceRules(){const e={},t=new Set,s=(n,o=null)=>{const c=n.style.getPropertyValue("src"),g=n.style.getPropertyValue("font-family").replace(/['"]/g,"").trim(),h=n.style.getPropertyValue("font-weight")||"400",u=n.style.getPropertyValue("font-style")||"normal";e[g]||(e[g]={urls:[],variations:new Set});const d=(f=>{if(!f)return null;const p=f.match(/url\s*\(\s*(['"]?)(.+?)\1\s*\)/);return p?p[2]:null})(c);if(d){let f=d;o&&(f=new URL(f,o).href);const p=this.cleanUrl(f);e[g].urls.includes(p)||(e[g].urls.push(p),e[g].variations.add(JSON.stringify({weight:h,style:u})))}},i=async n=>{try{const o=n.href;if(t.has(o))return;t.add(o);const c=await fetch(o,{mode:"cors"});if(!c.ok){this.logger.logMessage(`Failed to fetch @import CSS: ${c.status}`);return}const g=await c.text(),h=new CSSStyleSheet;h.replaceSync(g),Array.from(h.cssRules||[]).forEach(u=>{u instanceof CSSFontFaceRule&&s(u,o)})}catch(o){this.logger.logMessage(`Error processing @import rule: ${o.message}`)}},l=async n=>{try{const o=Array.from(n.cssRules||[]);for(const c of o)c instanceof CSSFontFaceRule?s(c,n.href):c instanceof CSSImportRule?c.styleSheet?await l(c.styleSheet):await i(c):c.styleSheet&&await l(c.styleSheet)}catch(o){if(o.name==="SecurityError"&&n.href){if(t.has(n.href))return;t.add(n.href);try{const c=await fetch(n.href,{mode:"cors"});if(c.ok){const g=await c.text(),h=new CSSStyleSheet;h.replaceSync(g),Array.from(h.cssRules||[]).forEach(d=>{d instanceof CSSFontFaceRule&&s(d,n.href)});const u=/@import\s+url\(['"]?([^'")]+)['"]?\);?/g;let m;for(;(m=u.exec(g))!==null;){const d=new URL(m[1],n.href).href;if(!t.has(d)){t.add(d);try{const f=await fetch(d,{mode:"cors"});if(f.ok){const p=await f.text(),S=new CSSStyleSheet;S.replaceSync(p),Array.from(S.cssRules||[]).forEach(y=>{y instanceof CSSFontFaceRule&&s(y,d)})}}catch(f){this.logger.logMessage(`Error fetching @import ${d}: ${f.message}`)}}}}}catch(c){this.logger.logMessage(`Error fetching stylesheet ${n.href}: ${c.message}`)}}else this.logger.logMessage(`Error processing stylesheet: ${o.message}`)}},r=Array.from(document.styleSheets);for(const n of r)await l(n);const a=document.querySelectorAll("style");for(const n of a){const o=n.textContent||n.innerHTML||"",c=/@import\s+url\s*\(\s*['"]?([^'")]+)['"]?\s*\)\s*;?/g;let g;for(;(g=c.exec(o))!==null;){const h=g[1];if(!t.has(h)){t.add(h);try{const u=await fetch(h,{mode:"cors"});if(u.ok){const m=await u.text(),d=new CSSStyleSheet;d.replaceSync(m),Array.from(d.cssRules||[]).forEach(f=>{f instanceof CSSFontFaceRule&&s(f,h)})}}catch(u){this.logger.logMessage(`Error fetching inline @import ${h}: ${u.message}`)}}}}return Object.values(e).forEach(n=>{n.variations=Array.from(n.variations).map(o=>JSON.parse(o))}),e}isElementAboveFold(e){if(!this.isElementVisible(e))return!1;const t=e.getBoundingClientRect(),s=window.pageYOffset||document.documentElement.scrollTop,i=t.top+s,l=window.innerHeight||document.documentElement.clientHeight;return i<=l}canElementBeProcessed(e){return this.canElementBeStyledWithFontFamily(e)&&this.isElementAboveFold(e)}async run(){await document.fonts.ready,await this._initializeExternalFontSheets();const e=this.getNetworkLoadedFonts(),t=await this.getFontFaceRules(),s=new Map,i=await this.processExternalFonts(this.externalParsedPairs);Array.from(document.getElementsByTagName("*")).filter(a=>this.canElementBeProcessed(a)).forEach(a=>{const n=(o,c=null)=>{if(!o||!this.isElementVisible(a))return;const g=o.fontFamily.split(",")[0].replace(/['"]+/g,"").trim();if((c?o.content!=="none"&&o.content!=='""':a.textContent.trim())&&t[g]){let u=t[g].urls;!this.isExcluded(g,u)&&!s.has(g)&&(s.set(g,{elements:new Set,urls:u,variations:t[g].variations}),s.get(g).elements.add(a))}};try{n(window.getComputedStyle(a)),["::before","::after"].forEach(o=>{n(window.getComputedStyle(a,o),o)})}catch(o){this.logger.logMessage("Error processing element:",o)}});const r=this.summarizeMatches(i,s,e);if(!Object.keys(r.allFonts).length&&!Object.keys(r.externalFonts).length&&!Object.keys(r.hostedFonts).length){this.logger.logMessage("No fonts found above the fold.");return}this.logger.logMessage("Above the fold fonts:",r),this.aboveTheFoldFonts=[...new Set(Object.values(r.allFonts).flatMap(a=>a.variations.map(n=>n.url)))]}summarizeMatches(e,t,s){const i={},l={};return t.size>0&&t.forEach((r,a)=>{if(r.variations){const n=Array.from(r.elements),o=n.filter(g=>this.isElementAboveFold(g)),c=n.filter(g=>!this.isElementAboveFold(g));r.variations.forEach(g=>{let h=null;for(const u of r.urls){const m=this.cleanUrl(u);if(s.has(m)){h=s.get(m);break}}h&&(i[a]||(i[a]={type:"hosted",variations:[],elementCount:{aboveFold:o.length,belowFold:c.length,total:n.length},urlCount:{aboveFold:new Set,belowFold:new Set}}),i[a].variations.push({weight:g.weight,style:g.style,url:h,elementCount:{aboveFold:o.length,belowFold:c.length,total:n.length}}),o.length>0&&i[a].urlCount.aboveFold.add(h),c.length>0&&i[a].urlCount.belowFold.add(h))}),i[a]&&(l[a]={variations:i[a].variations,elementCount:{...i[a].elementCount},urlCount:{...i[a].urlCount}})}}),Object.keys(e).length>0&&Object.entries(e).forEach(([r,a])=>{const n=Array.from(a.elements).filter(c=>this.isElementAboveFold(c)),o=Array.from(a.elements).filter(c=>!this.isElementAboveFold(c));(a.elementCount.aboveFold>0||n.length>0)&&a.variations.forEach(c=>{i[c.family]||(i[c.family]={type:"external",variations:[],elementCount:{aboveFold:0,belowFold:0,total:0},urlCount:{aboveFold:new Set,belowFold:new Set}}),i[c.family].variations.push({weight:c.weight,style:c.style,url:r,elementCount:{aboveFold:n.length,belowFold:o.length,total:a.elements.length}}),i[c.family].elementCount.aboveFold+=n.length,i[c.family].elementCount.belowFold+=o.length,i[c.family].elementCount.total+=a.elements.length,n.length>0&&i[c.family].urlCount.aboveFold.add(r),o.length>0&&i[c.family].urlCount.belowFold.add(r)})}),Object.values(i).forEach(r=>{r.urlCount={aboveFold:r.urlCount.aboveFold.size,belowFold:r.urlCount.belowFold.size,total:new Set([...r.urlCount.aboveFold,...r.urlCount.belowFold]).size}}),Object.values(l).forEach(r=>{r.urlCount.aboveFold instanceof Set&&(r.urlCount={aboveFold:r.urlCount.aboveFold.size,belowFold:r.urlCount.belowFold.size,total:new Set([...r.urlCount.aboveFold,...r.urlCount.belowFold]).size})}),{externalFonts:Object.fromEntries(Object.entries(e).filter(r=>r[1].elementCount.aboveFold>0)),hostedFonts:l,allFonts:i}}async processExternalFonts(e){const t=new Map,s=Array.from(document.getElementsByTagName("*")).filter(r=>this.canElementBeProcessed(r)),i=new Map;Object.entries(e).forEach(([r,a])=>{a.forEach(n=>{const o=`${n.family}|${n.weight}|${n.style}`;i.set(o,{url:r,...n})})});const l=r=>{const a=r.fontFamily.split(",")[0].replace(/['"]+/g,"").trim(),n=r.fontWeight,o=r.fontStyle,c=`${a}|${n}|${o}`;let g=i.get(c);if(!g&&n!=="400"){const h=`${a}|400|${o}`;g=i.get(h)}return g};return s.forEach(r=>{if(r.textContent.trim()){const a=window.getComputedStyle(r),n=l(a);n&&!this.isExcluded(n.family,[n.url])&&!t.has(n.url)&&(t.set(n.url,{elements:new Set,variations:new Set}),t.get(n.url).elements.add(r),t.get(n.url).variations.add(JSON.stringify({family:n.family,weight:n.weight,style:n.style})))}["::before","::after"].forEach(a=>{const n=window.getComputedStyle(r,a);if(n.content!=="none"&&n.content!=='""'){const o=l(n);o&&!this.isExcluded(o.family,[o.url])&&!t.has(o.url)&&(t.set(o.url,{elements:new Set,variations:new Set}),t.get(o.url).elements.add(r),t.get(o.url).variations.add(JSON.stringify({family:o.family,weight:o.weight,style:o.style})))}})}),Object.fromEntries(Array.from(t.entries()).map(([r,a])=>[r,{elementCount:{aboveFold:Array.from(a.elements).filter(n=>this.isElementAboveFold(n)).length,total:a.elements.size},variations:Array.from(a.variations).map(n=>JSON.parse(n)),elements:Array.from(a.elements)}]))}getResults(){return this.aboveTheFoldFonts}},A=B,R=class{constructor(e,t){this.logger=t,this.result=[],this.excludedPatterns=e.preconnect_external_domain_exclusions,this.eligibleElements=e.preconnect_external_domain_elements,this.matchedItems=new Set,this.excludedItems=new Set}async run(){document.querySelectorAll(`${this.eligibleElements.join(", ")}[src], ${this.eligibleElements.join(", ")}[href], ${this.eligibleElements.join(", ")}[rel], ${this.eligibleElements.join(", ")}[type]`).forEach(t=>this.processElement(t)),this.logger.logMessage({matchedItems:this.getMatchedItems(),excludedItems:Array.from(this.excludedItems)})}processElement(e){try{const t=new URL(e.src||e.href||"",location.href);if(this.isExcluded(e)){this.excludedItems.add(this.createExclusionObject(t,e));return}this.isExternalDomain(t)&&(this.matchedItems.add(`${t.hostname}-${e.tagName.toLowerCase()}`),this.result=[...new Set(this.result.concat(t.origin))])}catch(t){this.logger.logMessage(t)}}isExcluded(e){const t=e.outerHTML.substring(0,e.outerHTML.indexOf(">")+1);return this.excludedPatterns.some(s=>t.includes(s))}isExcludedByDomain(e){return this.excludedPatterns.some(t=>t.type==="domain"&&e.hostname.includes(t.value))}isExternalDomain(e){return e.hostname!==location.hostname&&e.hostname}createExclusionObject(e,t){return{domain:e.hostname,elementType:t.tagName.toLowerCase()}}getMatchedItems(){return Array.from(this.matchedItems).map(e=>{const t=e.lastIndexOf("-");return[e.substring(0,t),e.substring(t+1)]})}getResults(){return this.result}},I=R,T=class{constructor(e){this.enabled=e}logMessage(e,t=""){if(this.enabled){if(t!==""){console.log(e,t);return}console.log(e)}}logColoredMessage(e,t="green"){this.enabled&&console.log(`%c${e}`,`color: ${t};`)}},P=T,L=class{constructor(e){this.config=e,this.lcpBeacon=null,this.lrcBeacon=null,this.preloadFontsBeacon=null,this.preconnectExternalDomainBeacon=null,this.infiniteLoopId=null,this.errorCode="",this.logger=new P(this.config.debug)}async init(){if(this.scriptTimer=new Date,!await this._isValidPreconditions()){this._finalize();return}if(E.isPageScrolled()){this.logger.logMessage("Bailing out because the page has been scrolled"),this._finalize();return}this.infiniteLoopId=setTimeout(()=>{this._handleInfiniteLoop()},1e4);const e=await this._getGeneratedBefore(),t=this.config.status.atf&&(e===!1||e.lcp===!1),s=this.config.status.lrc&&(e===!1||e.lrc===!1),i=this.config.status.preload_fonts&&(e===!1||e.preload_fonts===!1),l=this.config.status.preconnect_external_domain&&(e===!1||e.preconnect_external_domain===!1);t?(this.lcpBeacon=new v(this.config,this.logger),await this.lcpBeacon.run()):this.logger.logMessage("Not running BeaconLcp because data is already available or feature is disabled"),s?(this.lrcBeacon=new M(this.config,this.logger),await this.lrcBeacon.run()):this.logger.logMessage("Not running BeaconLrc because data is already available or feature is disabled"),i?(this.preloadFontsBeacon=new A(this.config,this.logger),await this.preloadFontsBeacon.run()):this.logger.logMessage("Not running BeaconPreloadFonts because data is already available or feature is disabled"),l?(this.preconnectExternalDomainBeacon=new I(this.config,this.logger),await this.preconnectExternalDomainBeacon.run()):this.logger.logMessage("Not running BeaconPreconnectExternalDomain because data is already available or feature is disabled"),t||s||i||l?this._saveFinalResultIntoDB():(this.logger.logMessage("Not saving results into DB as no beacon features ran."),this._finalize())}async _isValidPreconditions(){const e={width:this.config.width_threshold,height:this.config.height_threshold};return E.isNotValidScreensize(this.config.is_mobile,e)?(this.logger.logMessage("Bailing out because screen size is not acceptable"),!1):!0}async _getGeneratedBefore(){if(!E.isPageCached())return!1;let e=new FormData;return e.append("action","rocket_check_beacon"),e.append("rocket_beacon_nonce",this.config.nonce),e.append("url",this.config.url),e.append("is_mobile",this.config.is_mobile),(await fetch(this.config.ajax_url,{method:"POST",credentials:"same-origin",body:e}).then(s=>s.json())).data}_saveFinalResultIntoDB(){const e={lcp:this.lcpBeacon?this.lcpBeacon.getResults():null,lrc:this.lrcBeacon?this.lrcBeacon.getResults():null,preload_fonts:this.preloadFontsBeacon?this.preloadFontsBeacon.getResults():null,preconnect_external_domain:this.preconnectExternalDomainBeacon?this.preconnectExternalDomainBeacon.getResults():null},t=new FormData;t.append("action","rocket_beacon"),t.append("rocket_beacon_nonce",this.config.nonce),t.append("url",this.config.url),t.append("is_mobile",this.config.is_mobile),t.append("status",this._getFinalStatus()),t.append("results",JSON.stringify(e)),fetch(this.config.ajax_url,{method:"POST",credentials:"same-origin",body:t,headers:{"wpr-saas-no-intercept":!0}}).then(s=>s.json()).then(s=>{this.logger.logMessage(s.data.lcp)}).catch(s=>{this.logger.logMessage(s)}).finally(()=>{this._finalize()})}_getFinalStatus(){return this.errorCode!==""?this.errorCode:10<=(new Date-this.scriptTimer)/1e3?"timeout":"success"}_handleInfiniteLoop(){this._saveFinalResultIntoDB()}_finalize(){document.querySelector('[data-name="wpr-wpr-beacon"]').setAttribute("beacon-completed","true"),clearTimeout(this.infiniteLoopId)}},_=L;(e=>{if(!e)return;const t=new _(e);if(document.readyState!=="loading"){setTimeout(()=>{t.init()},e.delay);return}document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>{t.init()},e.delay)})})(window.rocket_beacon_data);var N=_})(); //# sourceMappingURL=wpr-beacon.min.js.map